<?php
require_once realpath (dirname (__FILE__) . '//..//pages.php');
require_once INC_FUNCTIONS;
require_once MDL_TABLES;

$stats = getStats ();
/* Preparing previous and next tables */
$keys = array_keys ($stats);
$key = array_search ($stat, $keys);
if ($key || $key == 0) {
    if (isset ($keys[$key - 1])) {
        $l = $keys[$key - 1];
        $l_label = $stats[$keys[$key - 1]];
    } else {
        $l = null;
    }
    if (isset ($keys[$key + 1])) {
        $r = $keys[$key + 1];
        $r_label = $stats[$keys[$key + 1]];
    } else {
        $r = null;
    }
} else {
    $l = null;
    $r = null;
}
/**/
authorize ();

if (isset ($html)) {
    if (!is_a ($html, 'Div')) {
        notify ('Invalid data!');
        exit ();
    }
} else {
    notify ('No data to load!');
    exit ();
}
if (!isset ($stat) || empty ($stat)) {
    notify ('No table to load!');
    exit ();
}

echo doctype ();
?>
<html>
    <?php echo head (PAGE_TITLE, array (HTTP_CSS_MENU, HTTP_CSS_STATS, HTTP_CSS_STYLE)); ?>
    <body>
        <?php require_once VW_MENU; ?>
        <h1 class="fixed"><?php echo $stats[$stat]; ?></h1>
        <hr class="vertical" />
        <?
        echo $html->__toString ();
        ?>
        <?php if ($l) : ?>
            <div class="previous">
                <!--<div class="chat-bubble fixed left_bubble">
                    Clicca qua per navigare tra le pagine
                    <div class="chat-bubble-arrow-border left"></div>
                    <div class="chat-bubble-arrow left"></div>
                </div>-->
                <a href="<?php echo HTTP_CTRL_MAIN . "?stat=$l"; ?>">
                    <div class="auto_margin" id="left-triangle"></div>
                    Vai a <?php echo $l_label; ?>
                </a>
            </div>
        <?php endif; ?>
        <?php if ($r) : ?>
            <div class="next">
                <!--<div class="chat-bubble fixed right_bubble">
                    Clicca qua per navigare tra le pagine
                    <div class="chat-bubble-arrow-border right"></div>
                    <div class="chat-bubble-arrow right"></div>
                </div>-->
                <a class="next" href="<?php echo HTTP_CTRL_MAIN . "?stat=$r"; ?>">
                    <div class="auto_margin" id="right-triangle"></div>
                    Vai a <?php echo $r_label; ?>
                </a>
            </div>
        <?php endif; ?>
    </body>
</html>
